<extend name="Public/base"/>

<block name="body">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{$title}</h2>
    </div>
    <!--搜索栏-->
    <div class="cf" style="margin-bottom: 10px;">
        <span>批次号:</span>
        <input style="height: 25px;" type="text" id="pici_id" name="pici_id" class="search-input" value="{$search_info.pici_id}" placeholder="">
        <span style="margin-left: 25px;">批次名称:</span>
        <input style="height: 25px;" type="text" id="pici_name" name="pici_name" class="search-input" value="{$search_info.pici_name}" placeholder="">
        <span style="margin-left: 25px;">产品编码:</span>
        <input style="height: 25px;" type="text" id="p_id" name="p_id" class="search-input" value="{$search_info.p_id}" placeholder="">
        <span style="margin-left: 25px;">产品名称:</span>
        <input style="height: 25px;" type="text" id="name" name="name" class="search-input" value="{$search_info.name}" placeholder="">
        <button style="margin-left: 25px;height: 27px;line-height: 8px;" class="btn" onClick='query()'>查  询</button>
    </div>
    <div class="cf">
        <div class="fl">
            <button class="btn" id="detail" onclick="detail()">查询详情</button>
            <button class="btn" id="Printing" onclick="printing()">打印二维码</button>
            <button class="btn" id="dl" onclick="dl()">下载二维码</button>
            <button class="btn" id="del" onclick="del()">删  除</button>
            <a href="#" download hidden id="links" ></a>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data">
        <table>
            <thead>
            <tr>
                <th class="public_tanle_qianmian"></th>
                <th class="public_tanle_qianmian">序号</th>
                <th class="public_tanle_qianmian">批次号</th>
                <th class="public_tanle_qianmian">批次名称</th>
                <th class="public_tanle_qianmian">产品编码</th>
                <th class="public_tanle_qianmian">产品名称</th>
                <th class="public_tanle_qianmian">数量</th>
                <th class="public_tanle_qianmian">促销员绑定</th>
                <th class="public_tanle_qianmian">消费者绑定</th>
                <th class="public_tanle_qianmian">生成时间</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="list">
                <volist name="list" id="list_vo">
                    <tr>
                        <td class="public_content_qianmian"><input type="radio" name="id" value="{$list_vo.id}" style="margin: 0 auto"></td>
                        <td class="public_content_qianmian">{$list_vo.number|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.pici_id|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.pici_name|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.p_id|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.name|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.create_num|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.cuxiao_num|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.xiaofei_num|default='--'}</td>
                        <td class="public_content_qianmian">{$list_vo.create_time|default='--'}</td>
                    </tr>
                </volist>
                <else/>
                <td colspan="100" class="text-center"> 暂时没有内容 </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <!-- 分页 -->
    <div class="page">
        {$page}
    </div>
</block>

<block name="script">
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <!-- 引入CSS、JS开始 -->
    <link href="__CSS__/wash_helper/gm_table_public.css" rel="stylesheet" type="text/css">
    <!-- 引入CSS、JS结束 -->
    <script type="text/javascript">
        /* 当前子菜单栏高亮 */
        highlight_subnav('{:U('QRcode/qrcode_admin')}');

        query = function query(){
            var url = "/wash_helper/index.php?s=/Admin/QRcode/qrcode_admin";
            var pici_id = $('#pici_id').val();
            var pici_name = $('#pici_name').val();
            var p_id = $('#p_id').val();
            var name = $('#name').val();

            if(pici_id != ""){
                url += "/pici_id/" + pici_id;
            }
            if(pici_name != ""){
                url += "/pici_name/" + pici_name;
            }
            if(p_id != ""){
                url += "/p_id/" + p_id;
            }
            if(name != ""){
                url += "/name/" + name;
            }

            window.location.href = url;
        };

        detail = function detail(){
            var id = $("input[name='id']:checked").val();
            if(id){
                var detail_url = "/wash_helper/index.php?s=/Admin/QRcode/pici_detail";
                detail_url += "/id/" + id;

                window.location.href = detail_url;
            }else{
                alert('请选择一个批次后，再执行该操作~');
            }
        };

        printing = function printing(){
            var id = $("input[name='id']:checked").val();
            if(id){
                $.post(
                    "{:U('QRcode/qrcode_detail')}",
                    {id:id},
                    function(result){
                        var printing_url = '/wash_helper/Uploads/QRcode/pdf/'+result;
                        window.open(printing_url);//在新窗口打开
                    }
                );
            }else{
                alert('请选择一个批次后，再执行该操作~');
            }
        };

        dl = function dl(){
            var id = $("input[name='id']:checked").val();
            if(id){
                $.post(
                    "{:U('QRcode/qrcode_download')}",
                    {id:id},
                    function(result){
                        var dl_url = '/wash_helper/Uploads/QRcode/zip/'+result;
                        $('#links').prop('href',dl_url);
                        //将 $('#links') 转换为 JS 对象，然后触发 click 事件。
                        $('#links')[0].click();
                    }
                );
            }else{
                alert('请选择一个批次后，再执行该操作~');
            }
        };

        del = function del(){
            var id = $("input[name='id']:checked").val();
            if(id){
                if(!confirm('删除将不可恢复，确认删除吗？')){
                    return false;
                }

                $.post(
                    "{:U('QRcode/qrcode_del')}",
                    {id:id},
                    function(result){
                        // console.log(result);
                        if(result == '200'){
                            location.reload();
                        }else if(result == '405'){
                            alert('已有促销员绑定，不可删除~');
                        }else if(result == '406'){
                            alert('已有消费者绑定，不可删除~');
                        }else{
                            alert(result);
                        }
                    }
                );
            }else{
                alert('请选择一个批次后，再执行该操作~');
            }
        };
    </script>
</block>